﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CRM.Admin.Contracts.Contract.Customer;
using CRM.Admin.Contracts.Dto.Customer;
using CRM.Admin.Contracts.Model.Customer;
using KingsSharp.Common;
using KingsSharp.Common.Data;
using KingsSharp.Core;
using KingsSharp.Core.Data;

namespace CRM.Admin.Services.Service.Customer
{
    public class CustomerNatureService : ServiceBase, ICustomerNatureService
    {
        private IRepository<CustomerNature, Guid> CustomerNatureRepository;
        public CustomerNatureService(IRepository<CustomerNature, Guid> _CustomerNatureRepository)
            :base(_CustomerNatureRepository.UnitOfWork)
        {
            CustomerNatureRepository = _CustomerNatureRepository;
        }

        public IQueryable<CustomerNature> Natures{get {return CustomerNatureRepository.Entities;}}

        public OperationResult Delete(params Guid[] ids)
        {
            var entitys = CustomerNatureRepository.Entities.Where(a => ids.Contains(a.Id)).ToList();
            entitys.ForEach(a => a.IsDeleted = true);
            int result = CustomerNatureRepository.Update(entitys.ToArray());
            return new KingsSharp.Common.Data.OperationResult(KingsSharp.Common.Data.OperationResultType.Success, "删除成功");
        }

        public OperationResult Insert(params CustomerNatureDto[] dtos)
        {
            dtos.CheckNotNull("dtos");
            foreach (var t in dtos)
            {
                t.Id = Guid.NewGuid();
            }
            var result = CustomerNatureRepository.Insert(dtos);
            return result;
        }

        public OperationResult Update(params CustomerNatureDto[] dtos)
        {
            dtos.CheckNotNull("dtos");
            var result = CustomerNatureRepository.Update(dtos);
            return result;
        }
    }
}
